<template>
	<view class="student-wrap">
		<u-navbar
			backIconColor="#FFFFFF"
			:background="{background: 'linear-gradient(90deg,#615CED,#8286F2)'}"
			:border-bottom="false"
			title="学生信息"
			titleColor="#FFFFFF"
			height="88">
		</u-navbar>

		<view class="personinfo">
			<image class="topbg" src="../../static/student_bg_top.png" mode="scaleToFill"></image>
			<view class="infomore">
				<image :src="baseUrl+details.certificates" mode=""></image>
				<view class="inforight">
					<view class="name">{{`${details.name?details.name:''} ${details.Gender?details.Gender:''}`}}</view>
					<view class="zhengjian">证件号码：{{details.certificates_number?details.certificates_number:''}}</view>
					<view class="birthday">
						出生年月：{{details.birth_date?details.birth_date:''}}
					</view>
					<view class="minzu">
						民族：{{details.nation?details.nation:''}}
					</view>
					<view class="jiguan">
						籍贯：{{details.native_place?details.native_place:''}}
					</view>
				</view>
			</view>
		</view>

		<view class="baokaoinfo">
			<view class="infolist">
				<view class="title">考生报考信息</view>
				<view class="infoitem">
					<view class="lefttext">
						<p>持有证书：</p>
						<p>报考专业：</p>
						<p>报考等级：</p>
						<p>考试时间：</p>
						<p>考试地点：</p>
						<p>考室：</p>
						<p>准考证号：</p>
					</view>

					<view class="righttext">
						<p>{{details.certificate?details.certificate:'无等级'}}</p>
						<p>{{details.major?details.major:'--'}}</p>
						<p>{{details.Grade?details.Grade:'--'}}</p>
						<p>{{details.VideoUploadTime?details.VideoUploadTime:'--'}}</p>
						<p>{{details.examination_place?details.examination_place:'--'}}</p>
						<p>{{details.examination_room?details.examination_room:'--'}}</p>
						<p>{{details.examination_number?details.examination_number:'--'}}</p>
					</view>
				</view>
			</view>
			<!-- <view style="height: 330rpx;"></view> -->
			<view class="bottom-fixed">
				<view class="luzhi" v-if="details.registration_method == 2">
					<!-- <view class="videoluzhi" @click="recordVideo2">
						视频录制
					</view> -->
					<view class="pingshen" @click="writeCheck">
						开始评审(同时录制)
					</view>
				</view>
				<view class="pingshen2" v-else @click="writeCheck">
					开始评审(同时录制)
				</view>
				<view class="tishi">
					<view class="xinghao">*</view>
					<view class="tswenzi">
						温馨提示：确认好学生信息再开始评审哟
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import { uploadImg, uploadVid } from '@/js_sdk/shaoin-upload/upload.js'
export default {
	data() {
		return {
			id: '',
			baseUrl: this.$api.baseUrl,
			details: {},
			ossUrl: 'https://yuyin-online.oss-cn-shanghai.aliyuncs.com',
			accessKeyId: '',
			accessKeySecret: '',
			timeout: '',
			maxSize: '',
			Expiration: ''
		}
	},
	onLoad(ops) {
		console.warn(ops)
		this.id = ops?.id || ''
		this.id && this.getDetails()
	},
	methods: {
		getCurrentDate() {
			const currentDate = new Date();
			const year = currentDate.getFullYear();
			const month = String(currentDate.getMonth() + 1).padStart(2, '0'); 
			const day = String(currentDate.getDate()).padStart(2, '0');
			return `${year}${month}${day}`;
		},
		recordVideo2() {
			try{
				const systemInfo = uni.getSystemInfoSync()
				this.getApi(this.$api.transcribe, {
					id: this.id,
					device_id: systemInfo.deviceId
				}).then(res => { 
					if (res.code) {
						
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}
				})
			}catch(e){
				console.warn(e)
			}
		},
		recordVideo() {
			uni.showLoading({
				title: '',
				mask: true
			})
			this.getApi(this.$api.upload_video,{
				id: this.id
			}).then(res => {
				if(res.code == 1) {
					this.getApi(this.$api.userpolicy,{
						id: this.id
					}).then(res => {
						uploadVid(`offline_video/${this.getCurrentDate()}/`, res.data, this.id, this.$auth.token(this.$api.assessment), this.details.name?this.details.name:'').then(async res => {
							let params = {
								id: this.id,
								video: `/${res}`
							}
							let _res = await this.getApi(this.$api.upload_video, params, 'POST')
							console.log('------------',_res);
							uni.showToast({
								title: _res.msg,
								icon: 'none',
							})
						})
					})
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none',
					})
				}
			})
		},
		getApi(url, data = {}, method = 'GET') {
			return new Promise((reslove, reject) =>{
				uni.request({
					url: `${this.$api.baseUrl}${url}`,
					method,
					timeout: 30000,
					data,
					header: {
						'authtoken': this.$auth.token(this.$api.assessment)
					},
					success: res => {
						console.warn('--------------',res)
						reslove(res.data)
					},
					fail(err) {
						console.warn('--------------',err)
						reject(err)
					},
					complete() {
						uni.hideLoading()
					}
				})
			})
		},
		
		writeCheck() {
			uni.showLoading({
				title: '准备评审...',
				mask: true
			})
			let ctx = this
			const systemInfo = uni.getSystemInfoSync()
			uni.request({
				url: `${ctx.$api.baseUrl}${ctx.$api.assessment}`,
				method: 'GET',
				timeout: 30000,
				data: {
					id: ctx.id,
					device_id: systemInfo.deviceId
				},
				header: {
					'authtoken': ctx.$auth.token(ctx.$api.assessment)
				},
				success(res) {
					if (res.data?.code == 1) {
						if (res?.data?.data?.major == 23) {
							// 听力
							uni.navigateTo({
								url: `../check/hearing?id=${ctx.id}`
							})
						} else {
							// 非听力
							uni.navigateTo({
								url: `../check/nonHearing?id=${ctx.id}`
							})
						}
					} else {
						uni.showToast({
							title: res.data?.msg || '获取评审失败',
							icon: 'none',
						})
					}
				},
				fail(err) {
					uni.showToast({
						title: '获取评审失败',
						icon: 'none',
					})
				},
				complete() {
					uni.hideLoading()
				}
			})
		},
		getDetails() {
			let ctx = this
			uni.request({
				url: `${ctx.$api.baseUrl}${ctx.$api.candidateDetails}`,
				method: 'POST',
				timeout: 30000,
				data: {
					id: ctx.id
				},
				header: {
					'authtoken': ctx.$auth.token(ctx.$api.candidateDetails)
				},
				success(res) {
					if (res.data?.code == 1) {
						ctx.details = res?.data?.data
					} else {
						uni.showToast({
							title: res.data?.msg || '获取数据失败',
							icon: 'none',
						})
					}
				},
				fail(err) {
					uni.showToast({
						title: '获取数据失败',
						icon: 'none',
					})
				},
				complete() {}
			})
		},
	}
}
</script>

<style lang="scss" scoped>
page {
	background-color: #F8F8F8;
}
.student-wrap{
	.personinfo{
		width: 100%;
		height: 320rpx;
		position: relative;
		margin-top: -2rpx;
		.topbg{
			width: 100%;
			height: 320rpx;
			position: absolute;
			top: 0;
		}
		.infomore{
			display: flex;
			flex-direction: row;
			position: absolute;
			bottom: 70rpx;
			width: 100%;
			image{
				width: 150rpx;
				height: 200rpx;
				border-radius: 10rpx;
				margin-left: 40rpx;
				background-color: #666666;
			}
			.inforight{
				margin-left: 30rpx;
				.name{
					font-size: 30rpx;
					color: #FFFFFF;
					line-height: 30rpx;
					margin-top: 15rpx;
				}
				.zhengjian{
					font-size: 24rpx;
					color: #FFFFFF;
					line-height: 24rpx;
					margin-top: 30rpx;
				}
				.birthday{
					font-size: 24rpx;
					color: #FFFFFF;
					line-height: 24rpx;
					margin-top: 20rpx;
				}
				.minzu{
					font-size: 24rpx;
					color: #FFFFFF;
					line-height: 24rpx;
					margin-top: 20rpx;
				}
				.jiguan{
					font-size: 24rpx;
					color: #FFFFFF;
					line-height: 24rpx;
					margin-top: 20rpx;
				}
			}
		}
	}
	.baokaoinfo{
		width: 100%;
		margin-top: -30rpx;
		position: relative;
		padding-bottom: 50rpx;
		.infolist{
			width: 100%;
			background: #FFFFFF;
			border-radius: 20rpx;
			padding-bottom: 50rpx;
			.title{
				font-size: 30rpx;
				color: #333333;
				line-height: 30rpx;
				padding: 50rpx 0 0 40rpx;
			}
			.infoitem{
				display: flex;
				flex-direction: row;
				align-items: center;
				margin-left: 60rpx;
				.lefttext{
					p{
						font-size: 28rpx;
						color: #666666;
						line-height: 25rpx;
						margin-top: 40rpx;
					}
				}
				.righttext{
					margin-left: 50rpx;
					flex: 1;
					p{
						font-size: 28rpx;
						color: #333333;
						line-height: 25rpx;
						margin-top: 40rpx;
					}
				}
			}
		}
	}
	.bottom-fixed {
		width: 750rpx;
		height: 300rpx;
		display: flex;
		flex-direction: column;
		position: fixed;
		left: 0;
		bottom: 0;
		.luzhi{
			display: flex;
			padding-right: 75rpx;
			.videoluzhi{
				flex: 1;
				height: 90rpx;
				background: linear-gradient(0deg, #615CED, #8286F2);
				box-shadow: 0rpx 8rpx 15rpx 0rpx rgba(119, 163, 255, 0.28);
				border-radius: 45rpx;
				font-size: 36rpx;
				color: #FFFFFF;
				line-height: 90rpx;
				text-align: center;
				margin: 100rpx 0 0 75rpx;
			}
			.pingshen{
				flex: 1;
				height: 90rpx;
				background: linear-gradient(0deg, #615CED, #8286F2);
				box-shadow: 0rpx 8rpx 15rpx 0rpx rgba(119, 163, 255, 0.28);
				border-radius: 45rpx;
				font-size: 36rpx;
				color: #FFFFFF;
				line-height: 90rpx;
				text-align: center;
				margin: 100rpx 0 0 75rpx;
			}
		}
		.pingshen2{
			width: 600rpx;
			height: 90rpx;
			background: linear-gradient(0deg, #615CED, #8286F2);
			box-shadow: 0rpx 8rpx 15rpx 0rpx rgba(119, 163, 255, 0.28);
			border-radius: 45rpx;
			font-size: 36rpx;
			color: #FFFFFF;
			line-height: 90rpx;
			text-align: center;
			margin: 100rpx 0 0 75rpx;
		}
		.tishi{
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: center;
			margin-top: 30rpx;
			.xinghao{
				font-size: 24rpx;
				line-height: 24rpx;
				color: #FF5150;
			}
			.tswenzi{
				font-size: 24rpx;
				line-height: 24rpx;
				color: #FF5150;
			}
		}
	}
}
</style>